<template>
  <div class="caseManage">
    <el-tabs v-model="activeName" type="card" class="elTabs">
      <el-tab-pane name="first">
        <div slot="label" class="pageHeader">陈案管理</div>
      </el-tab-pane>
    </el-tabs>
    <div class="container">
      <!-- 搜索查询 -->
      <div class="searchBar" v-show="showSearch">
        <div class="searchForm">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
          >
            <el-form-item label="年份" prop="trendYear">
              <el-date-picker
                clearable
                v-model="queryParams.trendYear"
                type="year"
                value-format="yyyy"
                placeholder="请选择年份"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="案件名称" prop="caseName">
              <el-input
                v-model="queryParams.caseName"
                placeholder="请输入案件名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="案件阶段" prop="caseStatus">
              <el-select v-model="queryParams.caseStatus" placeholder="请选择案件阶段" clearable>
                <el-option
                  v-for="dict in dict.type.case_stage"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="完成状态" prop="compleStatus">
              <el-select v-model="queryParams.compleStatus" placeholder="请选择完成状态" clearable>
                <el-option
                  v-for="dict in dict.type.comple_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="searchButtons">
          <el-button class="searchButton" @click="handleQuery">搜索</el-button>
          <el-button class="resetButton" @click="resetQuery">重置</el-button>
        </div>
      </div>
      <div class="addDeleteBar">
        <el-button
          class="addButton"
          v-hasPermi="['supervision:chen:add']"
          @click.native="handleAdd"
        >
          <span class="plus">+</span>
          新增
        </el-button>
        <el-button
          @click="handleDelete"
          :class="!multiple ? 'deleteButton' : 'allDeleteButton'"
          :disabled="multiple"
          icon="el-icon-delete"
          v-hasPermi="['supervision:chen:remove']"
        >批量删除</el-button>
      </div>
      <!-- <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['supervision:chen:export']"
          >导出</el-button>
        </el-col>
      </el-row> -->
      <!-- 表单选择清空 -->
      <div class="tableSelectArea">
        <div>
          <div class="iconInfo el-icon-info"></div>
          <span class="infoText">已选择</span>
          <span class="infoText infoActive" v-text="selectedNum"></span>
          <span class="infoText">项</span>
          <span class="infoButton" @click="clearSelect">清空</span>
        </div>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </div>
      <el-table
        v-loading="loading"
        :data="chenList"
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        class="tableArea">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="年份" align="center" prop="trendYear" />
        <el-table-column label="案件名称" align="center" prop="caseName" />
        <el-table-column label="立案时间" align="center" prop="filingTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.filingTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="案件阶段" align="center" prop="caseStatus">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.case_stage" :value="scope.row.caseStatus" />
          </template>
        </el-table-column>
        <el-table-column
          label="案件详情"
          align="center"
          prop="caseDetails"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="完成状态" align="center" prop="compleStatus">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.comple_status" :value="scope.row.compleStatus" />
          </template>
        </el-table-column>
        <el-table-column  label="操作"
        width="180px" 
            fixed="right"
            align="left">
          <template slot-scope="scope">
            <div class="tableButtonArea">
              <!-- <el-button
                type="text"
                class="operationButton"
                v-if="scope.row.compleStatus === '0'"
                @click="handleComplete(scope.row)"
              >完成</el-button> -->
              <el-button type="text" class="operationButton" @click="handleDetail(scope.row)">详情</el-button>
              <el-button
                type="text"
                class="operationButton"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['supervision:chen:edit']"
              >修改</el-button>
              <el-button
                type="text"
                class="operationButton"
                @click="handleDelete(scope.row)"
                v-hasPermi="['supervision:chen:remove']"
              >删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <chenDetailModal :detailId.sync="detailId"> </chenDetailModal>

    <chenManageModal
      ref="chenManageModal"
      :modalType.sync="modalType"
      :id="id"
      @fatherMethod="fatherMethod"
    ></chenManageModal>
  </div>
</template>

<script>
import {
  listChen,
  getChen,
  delChen,
  addChen,
  updateChen,
} from "@/api/caseManage/caseChen/chen";

import chenDetailModal from "./components/chenDetailModal";

import chenManageModal from "./components/chenManageModal";

import { fatherMethod } from "@/utils/commonMethods";

import {
  MODALTYPE,
  CASESTATE,
  PAGESIZE,
  PAGENUM,
  DEPTTYPE,
  ROLETYPE,
  CASEEXPORTURL,
} from "@/utils/variable";

export default {
  name: "Chen",
  dicts: ["case_stage", "comple_status"],
  components: { chenDetailModal,chenManageModal },
  data() {
    return {
      id: 0,
      modalType: "",
      //详情页Id
      detailId: 0,
      activeName: "first",
      selectedNum: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 陈案处置情况表格数据
      chenList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openInfo: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        trendYear: null,
        caseName: null,
        caseStatus: null,
        compleStatus: null,
      },
      // 表单参数
      form: {},
      formInfo: {},
      // 表单校验
      rules: {
        trendYear: [
          { required: true, message: "年份不能为空", trigger: "blur" },
        ],
        caseName: [
          { required: true, message: "案件名称不能为空", trigger: "blur" },
        ],
        filingTime: [
          { required: true, message: "立案时间不能为空", trigger: "blur" },
        ],
        caseStatus: [
          { required: true, message: "案件阶段时间不能为空", trigger: "blur" },
        ],
        caseDetails: [
          { required: true, message: "案件详情不能为空", trigger: "blur" },
        ],
        compleStatus: [
          { required: true, message: "完成状态不能为空", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    dynamicWidth() {
      if (
        this.$store.state.user.dept.deptName == DEPTTYPE[7] ||
        this.$store.state.user.dept.deptName == DEPTTYPE[8]
      ) {
        return "100px";
      } else if (
        this.$store.state.user.dept.deptName == DEPTTYPE[5] ||
        this.$store.state.user.dept.deptName == DEPTTYPE[6] ||
        this.$store.state.user.dept.deptName == DEPTTYPE[2]
      ) {
        return "250px";
      } else {
        return "340px";
      }
    },
  },
  created() {
    this.getList();
  },
  methods: {
    fatherMethod,
    /** 详情按钮操作 */
     // 禁用当前年份及其以后的年份
    //  disabledDate(date) {
    //   const currentYear = new Date().getFullYear();
    //   return date.getFullYear() > currentYear;
    // },
    handleDetail(row) {
      this.detailId = row.id;
    },
    /** 新增按钮操作 */
    handleAdd() {
      console.log("点击了")
      this.modalType = MODALTYPE["新增"];
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.modalType = MODALTYPE["修改"];
      this.id = row.id;
    },
    /** 查询陈案处置情况列表 */
    getList() {
      this.loading = true;
      listChen(this.queryParams).then((response) => {
        this.chenList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        trendYear: null,
        caseName: null,
        filingTime: null,
        caseStatus: null,
        caseDetails: null,
        compleStatus: "0",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelect: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加陈案处置情况";
    // },
    /** 修改完成状态 */
    handleComplete(row) {
      row.compleStatus = "1";
      updateChen(row).then((response) => {
        this.$modal.msgSuccess("案件已完成");
        this.getList();
      });
    },
    //清空列表选择
    clearSelect() {
      this.$refs.multipleTable.clearSelection();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateChen(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addChen(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      let num = this.selectedNum;
      if (row.id) {
        num = 1;
      }
      this.$modal
        .confirm(`是否确认删除已选择的${num}条数据`)
        .then(function () {
          return delChen(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "supervision/chen/export",
        {
          ...this.queryParams,
        },
        `chen_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../../assets/styles/variables.scss";
.caseManage {
  height: 100%;
  .tableFooter {
    text-align: right;
    justify-content: flex-end;
    // margin-top: 25px;
    margin-right: 35px;
    // width: 100%;
    ::v-deep .btn-prev {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .btn-next {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .el-pager li {
      background-color: #fff;
      border: 1px solid #d4d3d3;
      font-size: 12px;
      font-family: $font-family;
      font-weight: 400;
      color: #5a5b5d;
    }
  }
  .el-form-item__label {
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    font-size: $form-label-font-size;
    color: $form-label-color;
  }

  .el-input__inner {
    font-size: $form-content-font-size;
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    // color: #AEAFB0;
  }
}
.input {
  width: 150px;
}
::v-deep .el-tabs--card .el-tabs__header {
  background-color: #e4e7ed;
}
::v-deep.el-tabs--card .el-tabs__header .el-tabs__item {
  border-radius: 10px solid black;
  background-color: #fff;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #053ef6;
  line-height: 48px;
  margin-top: 0;
}
</style>
